{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# SAKSHAT提供的DS18B20使用方法\n",
    "当前SAKSHAT为我们提供的方法参考：http://wiki.nxez.com/saks:sdk:libraries:ds18b20\n",
    "\n",
    "这里就直接摘录了，以下是创百科的内容:\n",
    "    \n",
    "DS18B20\n",
    "\n",
    "DS18B20温度传感器类，从传感器读取温度数据。方法如下:\n",
    "\n",
    "__init__(self, pin = 4)\n",
    "\n",
    "初始化对象，设置传感器数据引脚。\n",
    "\n",
    "is_exist(self, index = 0)\n",
    "\n",
    "返回传感器是否存在。true 或 false。存在多个传感器并联时 index 用于区分第几个传感器，编号从 0 开始。\n",
    "\n",
    "temperature(self, index = 0)\n",
    "\n",
    "返回当前传感器的温度数据，当传感器不存在或读取失败时返回 -128 度。存在多个传感器并联时 index 用于区分第几个传感器，编号从 0 开始。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#获取温度传感器温度，并进行显示\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        while True:        \n",
    "            #从 ds18b20 读取温度（摄氏度为单位）\n",
    "            temp = SAKS.ds18b20.temperature\n",
    "\n",
    "            #下方输出温度值\n",
    "            print (\"这就是我采集到的温度值\" + (\"%5.1f\" % temp).replace(' ','#'))\n",
    "            \n",
    "            #数码管显示温度\n",
    "            SAKS.digital_display.show((\"%5.1f\" % temp).replace(' ','#'))\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
